package com.otaku.crawler.util;

import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;

public class EmailHelper {
	private static final String host = "smtp.163.com";
	private static final int port = 994;
	private static final String userName = "doublezd@163.com";
	private static final String psw = "otakugame";
	private static final String to = "450266321@qq.com";
	private static final String subject = "CRAWLER INFO ON MY LAP";
	private static final String from = "doublezd@163.com";
	
	public static void sendMsg(String msg){
		try {
			Email e = new SimpleEmail();
			
			e.setHostName(host);
			e.setCharset("UTF-8");
//			e.setSmtpPort(port);
			e.setAuthentication(userName, psw);
			e.setFrom(from);
			e.setSubject(subject);
			e.setMsg(msg);
			e.addTo(to);
			e.send();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	public static void sendMsg(String msg,Exception e){
		EmailHelper.sendMsg(msg+"\n"+ExceptionUtil.getMessage(e));
	}
	
	public static void main(String[] args){
		sendMsg("我爱你");
	}
}
